﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using ZenSystemService.Api.Business;
using ZenSystemService.Api.Common.Auth;
using ZenSystemService.Api.DTOs;
using ZenSystemService.Api.DTOs.InstitutionOrder;
using ZenSystemService.Api.DTOs.TrainingReport;
using ZenSystemService.Api.Entities;
using ZenSystemService.Api.Services;

namespace ZenSystemService.Api.Controllers
{
    [Route("api/trainingReports")]
    [ApiController]
    public class TrainingReportController : ControllerBase
    {
        private readonly TrainingReportService _trainingReportService;


        public TrainingReportController(TrainingReportService trainingReportService)
        {
            _trainingReportService = trainingReportService;
        }

        /// <summary>
        /// 查询训练报告
        /// </summary>
        /// <returns></returns>
        [HttpPost("GetTrainingReports")]
        public async Task<IActionResult> GetTrainingReports(ReceiveObject _receiveObject)
        {
            var user = this.User.ToUserModel();
            var result = await _trainingReportService.GetTrainingReportsAsync(_receiveObject);
            return Ok(result);
        }

        [HttpPost("GetPagedTrainingReports")]
        public async Task<IActionResult> GetPagedTrainingReports(ReceiveObjectT<TrainingReportQueryRequestDTO> 
            _receiveObject)
        {
            var user = this.User.ToUserModel();
            var result = await _trainingReportService.GetTrainingReportsAsync(_receiveObject);
            return Ok(result);
        }

        [HttpPost("GetZenBrightTrainingReports")]
        public async Task<IActionResult> GetZenBrightTrainingReports(ReceiveObjectT<ZenBrightReportQueryRequestDTO>
            _receiveObject)
        {
            var user = this.User.ToUserModel();
            var result = await _trainingReportService.GetZenBrightReportsAsync(_receiveObject);
            return Ok(result);
        }

        [HttpPost("GetTrainingReportById")]
        public async Task<IActionResult> GetTrainingReportById(TrainingReportQueryByIdRequestDTO req)
        {
            var user = this.User.ToUserModel();
            var result = await _trainingReportService.GetTrainingReportByIdAsync(req);
            return Ok(result);
        }

        //[HttpPost("GetZenBrightTrainingReportByOrder")]
        //public async Task<IActionResult> GetZenBrightTrainingReportByOrder(ZenBrightReportQueryRequestDTO req)
        //{
        //    var user = this.User.ToUserModel();
        //    var result = await _trainingReportService.GetZenBrightTrainingReportByIdAsync(req);
        //    return Ok(result);
        //}


        /// <summary>
        /// 保存训练报告
        /// </summary>
        /// <param name="institutionSalesOrder"></param>
        /// <returns></returns>
        [HttpPost("CreateTrainingReport")]
        public async Task<IActionResult> CreateTrainingReport(TrainingReportCreateRequestDTO req)
        {
            ReturnObjectT<TrainingReportQueryResultDTO> _returnObject = new ReturnObjectT<TrainingReportQueryResultDTO>();

            var report = await _trainingReportService.CreateTrainingReportAsync(req);

            return new ObjectResult(new
                {
                    Message = "Training report saved successfully."
                })
                {
                    StatusCode = StatusCodes.Status201Created
                };
        }
    }
}